<?php

function send_email($to_email){

    $data['menber_id'] = mysqli_insert_id($GLOBALS['link']);//获取最近一条执行语句
    $data['keys_id'] = md5($to_email);//加密的注册帐号信息
    $data['cookie_time'] = time()+300;//激活有效时间

    // 存到激活表中
    add('active',$data);

    header("content-type:text/html;charset=utf-8");
    ini_set("magic_quotes_runtime",0);
    require LIB_PATH.'phpmailer/class.phpmailer.php';
    try {
        $mail = new PHPMailer(true); //创建一个邮件发送类对象
        $mail->IsSMTP(); //表示以smtp协议发送邮件
        $mail->CharSet='UTF-8'; //设置邮件的字符编码，这很重要，不然中文乱码
        // $mail->SMTPSecure='ssl'; //端口连接
        $mail->SMTPAuth   = true;                  //开启认证
        $mail->Port       = 25;                   //邮件发送服务端口  固定
        $mail->Host       = "smtp.163.com";       //服务器地址
        $mail->Username   = "18577808972@163.com";          //发送人帐号
        $mail->Password   = "1012494939myy";      //发送人授权码

        $mail->AddReplyTo("18577808972@163.com","mckee");//回复地址 参数1：回复人地址  参数2：昵称
        $mail->From       = "18577808972@163.com"; //发件人邮箱地址
        $mail->FromName   = "miss麦"; //发件人昵称


        $mail->AddAddress($to_email); //接收人帐号

        $to_email = md5($to_email);
        $mail->Subject  = "帐号激活";  //邮箱标题
        $mail->Body = "欢迎来到邮箱激活帐号页面，请点击这里<a href='http://localhost/cms/index.php?c=menber&a=active&keys=$to_email'>http://localhost/cms/index.php?c=menber&a=active&keys=$to_email</a>帐号";  //邮箱内容
        // $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; //当邮件不支持html时备用显示，可以省略
        // $mail->WordWrap   = 80; // 设置每行字符串的长度
        //$mail->AddAttachment("f:/test.png");  //可以添加附件
        $mail->IsHTML(true);  //以html格式发送
        $mail->Send();  //发送邮件
        echo '邮件已发送';
    } catch (phpmailerException $e) {
        echo "邮件发送失败：".$e->errorMessage();
    }
}

?>